<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<div class="aui-text-help-sm restore-tip mgb-16">
  {{'protection_oracle_restore_title_label' | i18n:[rowCopy?.resource_name, resourceEnvPro.version]}}
</div>
<lv-form [formGroup]="formGroup" class="formGroup" [lvLabelColon]='false'>
  <lv-form-item>
    <lv-form-label lvRequired>
      {{'protection_restore_to_label' | i18n}}
    </lv-form-label>
    <lv-form-control>
      <lv-radio-group formControlName="restoreTo">
        <lv-radio [lvValue]="restoreLocationType.ORIGIN">
          {{'common_restore_to_origin_location_label' | i18n}}
        </lv-radio>
      </lv-radio-group>
    </lv-form-control>
  </lv-form-item>
  <lv-form-item>
    <lv-form-label>
      {{'common_location_label' | i18n}}
    </lv-form-label>
    <lv-form-control>
      <input lv-input type='text' formControlName='location'/>
    </lv-form-control>
  </lv-form-item>
</lv-form>
<div class="mgt-10">
  <h2>{{'protection_select_file_label' |i18n}}</h2>
  <div class="mgt-10">
    <lv-collapse>
      <ng-container *ngFor="let item of tableDataArr; let i = index">
        <ng-template #totalTpl>
          {{'common_selected_simple_label' |i18n}}:
          <span class="total-icon">
            {{tableDataArr[i].selectedLength}}
          </span>
        </ng-template>
        <lv-collapse-panel [lvTitle]="item.title" [lvExtra]="totalTpl">
          <lv-tabs [(lvActiveIndex)]="tableDataArr[i].activeIndex" class="aui-tab">
            <lv-tab [lvTitle]="selectTitleTpl" [lvId]="'selecting'">
              <lv-group lvGutter="8px" class="mgb-8">
                <button lv-button [disabled]="!tableDataArr[i].selectedLength" lv-popover
                        [lvPopoverContent]="batchRestoreLocationTpl" lvPopoverTrigger="click" lvPopoverTheme="light"
                        lvPopoverPosition="bottom" #batchRestoreLocationPopover="lvPopover" (click)="openPopover(i)">
                  {{'protection_batch_set_restore_location_label' | i18n}}
                </button>
                <button lv-button (click)="resetAllRestoreLocation(i)">
                  {{'common_reset_label' | i18n}}
                </button>
                  <button lv-button (click)="selectAllFilesChange(i)" [disabled]="!_isNil(selectingIndex) && i!==selectingIndex">
                      {{(isAllCheck(i) ? 'system_resourceset_cancel_all_select_label':'system_resourceset_all_select_label') | i18n}}
                  </button>
              </lv-group>
              <lv-pro-table [config]="getSelectTableConfig(item)" [data]="item.data" #selectingTable></lv-pro-table>
              <aui-database-config [formGroup]="formGroup" [rowCopy]="rowCopy" *ngIf="item.id === 'param'"></aui-database-config>
            </lv-tab>
            <ng-template #selectTitleTpl>
              <span>{{'common_select_available_label'|i18n}}（{{tableDataArr[i].data.total}}）</span>
            </ng-template>
            <lv-tab [lvTitle]="selectedTitleTpl" [lvId]="'selected'">
              <button class="mgb-8" lv-button [disabled]="!tableDataArr[i].selectedLength" (click)="deleteAllItems(i)">
                {{'protection_clear_all_label' | i18n}}
              </button>
              <lv-pro-table [config]="getSelectedTableConfig(item)" [data]="selectionData[i]" #selectedTable> </lv-pro-table>
            </lv-tab>
            <ng-template #selectedTitleTpl>
              <span>{{'common_selected_label'|i18n}}（{{tableDataArr[i].selectedLength}}）</span>
            </ng-template>
          </lv-tabs>
        </lv-collapse-panel>
      </ng-container>
    </lv-collapse>
  </div>
</div>

<ng-template #restoreLocationExtraTpl let-item>
  <input lv-input [(ngModel)]="item.restoreLocation.value" (ngModelChange)="checkValid(item)" [ngClass]="{'error-input':item.restoreLocation.invalid}"/>
  <span *ngIf="item.restoreLocation.invalid" class="lv-form-control-error" style="margin-left: 5px;">
    {{ showErrorTipsLabel(item.restoreLocation,restoreLocationErrorTips) }}
  </span>
</ng-template>

<ng-template #restoreLocationTHExtraTpl>
  <i lv-icon="aui-icon-help"
     [lv-tooltip]="restorePathToolTips" lvTooltipPosition="rightTop" lvTooltipTheme="light" class="configform-constraint"
     lvColorState='true'></i>
</ng-template>

<ng-template #batchRestoreLocationTpl let-item>
  <lv-form [formGroup]="formGroup" class="formGroup mgb-16">
    <lv-form-item>
      <lv-form-label>
        {{'protection_recovery_target_pvc_label' | i18n}}
      </lv-form-label>
      <lv-form-control [lvErrorTip]="restoreLocationErrorTips">
        <input lv-input type="text" formControlName="batchRestoreLocationName"/>
      </lv-form-control>
    </lv-form-item>
  </lv-form>
  <div>
    <lv-group lvGutter='16px'>
      <button lv-button lvType='primary' (click)='batchSetRestoreLocation()'>
        {{ 'common_ok_label' | i18n }}
      </button>
      <button lv-button (click)='hideBatchRestoreLocationPopover()'>
        {{ 'common_cancel_label' | i18n }}
      </button>
    </lv-group>
  </div>
</ng-template>
